//microcommand define sitelen-esun
inject(["puppeteer"])
signature("<text:rawtext>")
action(async ({}, text) => {
  const p = await ctx.puppeteer.page()
  try {
    await p.goto("file:///root/koishi-app/assets/html/sitelen-esun/index.html")
    await p.evaluate(text => {
      const input = document.querySelector("textarea")
      input.value = text
      input.dispatchEvent(new Event("input"))
    }, text)
    await p.waitForNetworkIdle()
    return h.image(await p.evaluate(() => {
      const canvas = document.querySelector("canvas")
      return canvas.toDataURL("image/png")
    }))
  } finally {
    p.close()
  }
})